package cn.itcast.test;

import cn.itcast.dao.UserDao;
import cn.itcast.dao.imp.UserDaoImp;
import cn.itcast.domain.User;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.jdbc.core.JdbcTemplate;

import java.sql.*;
import java.util.List;

/**
 * @author: cuisensen
 * data: 2018/6/15.
 * time: 21:05.
 */
public class Demo01 {
    @Test
    public void test()
    {
        ApplicationContext applicationContext=new ClassPathXmlApplicationContext("applicationContext.xml");

        UserDao ud= (UserDao) applicationContext.getBean("userService");
        List<User> all = ud.getAll();
        System.out.println(all);
    }
    @Test
    public void test1() {
        try {
            Class.forName("com.mysql.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        Connection con = null;
        try {
            con= DriverManager.getConnection("jdbc:mysql://localhost:3306/xupt","root","root");
        } catch (SQLException e) {
            e.printStackTrace();
        }
        try {
            PreparedStatement prepareStatement=con.prepareStatement("select * from acu");
            ResultSet resultSet=prepareStatement.executeQuery();
            while(resultSet.next()){
                System.out.println(resultSet.getInt("id")+" "+resultSet.getString("name")+" "+resultSet.getDouble("money"));
            }
            con.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }

    }
}
